package edu.nf.ch07.container;

import io.github.classgraph.ClassGraph;
import io.github.classgraph.ClassInfo;
import io.github.classgraph.ClassInfoList;
import io.github.classgraph.ScanResult;

/**
 * @author wangl
 * @date 2025/4/16
 * 根据package扫描类
 */
public class ScanUtils {

    /**
     * 根据包名扫描相关的class
     * @param packageName 包名
     * @return 类集合
     */
    public static ClassInfoList scan(String packageName) {
        //创建ClassGraph对象
        ClassGraph graph = new ClassGraph();
        //指定扫描的包，并返回扫描的结果
        ScanResult result = graph.acceptPackages(packageName).scan();
        //从结果集中取出class集合并返回
        return result.getAllClasses();
    }


    public static void main(String[] args) {
        ClassInfoList list = scan("edu.nf.ch06");
        for (ClassInfo classInfo : list) {
            System.out.println(classInfo.getName());
        }
    }
}